import Vconsole from 'vconsole'
import { DEVELOPMENT } from '../constant'
import { isEmpty } from '../utils/common'

export const determineUseVConsole = () => {
  new Vconsole()
  if ((import.meta as any).env.MODE !== DEVELOPMENT) {
    hide()
  }
}

let count = 0
let lastClickTime = new Date().getTime()
const hide = () => {
  const vConsoleDom = document.getElementById('__vconsole')
  vConsoleDom?.setAttribute('style', 'display: none;')
}
const show = () => {
  const vConsoleDom = document.getElementById('__vconsole')
  vConsoleDom?.setAttribute('style', '')
}
const isShow = () => {
  const vConsoleDom = document.getElementById('__vconsole')
  return isEmpty(vConsoleDom?.style.display)
}
export const toggleVc = () => {
  const nowTime = new Date().getTime()
  if (nowTime - lastClickTime < 500) {
    count++
  } else {
    count = 0
  }
  lastClickTime = nowTime
  if (count >= 10) {
    if (isShow()) {
      hide()
    } else {
      show()
    }
    count = 0
  }
}
